package org.jeecg.modules.service.impl;

import cn.hutool.core.util.StrUtil;
import org.jeecg.modules.entity.RunnerMatchPlayer;
import org.jeecg.modules.mapper.RunnerMatchPlayerMapper;
import org.jeecg.modules.service.IRunnerMatchPlayerService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Description: 赛事人员
 * @Author: jeecg-boot
 * @Date:   2022-12-04
 * @Version: V1.0
 */
@Service
public class RunnerMatchPlayerServiceImpl extends ServiceImpl<RunnerMatchPlayerMapper, RunnerMatchPlayer> implements IRunnerMatchPlayerService {
	
	@Autowired
	private RunnerMatchPlayerMapper runnerMatchPlayerMapper;
	
	@Override
	public List<RunnerMatchPlayer> selectByMainId(String mainId) {
		return runnerMatchPlayerMapper.selectByMainId(mainId);
	}

	@Override
	public List<RunnerMatchPlayer> selectByMainIdNotEndTime(String mainId) {
		return runnerMatchPlayerMapper.selectByMainIdNotEndTime(mainId);
	}

	@Override
	public RunnerMatchPlayer selectByRingCode(String matchId,String ringCode) {
		Map<String ,Object> parms = new HashMap<>();
		parms.put("ringcode",ringCode);
		parms.put("mainId",matchId);
		List<RunnerMatchPlayer> players= runnerMatchPlayerMapper.selectByRingCode(parms);
		if(!players.isEmpty()){
			return players.get(0);
		}
		return null;
	}

	@Override
	public List<RunnerMatchPlayer> selectByMainIdAndGroupId(String mainId, List<String> groupids) {
		if(null!=groupids&&!groupids.isEmpty()){
			List<RunnerMatchPlayer> runnerMatchPlayers = new ArrayList<>();
			for(String groupid:groupids){
				Map<String,Object> parms = new HashMap<>();
				parms.put("mainId",mainId);
				parms.put("groupId",groupid);
				List<RunnerMatchPlayer> players = runnerMatchPlayerMapper.selectByMainIdAndGroupId(parms);
				runnerMatchPlayers.addAll(players);
			}
			return runnerMatchPlayers;
		}else {
			return runnerMatchPlayerMapper.selectByMainId(mainId);
		}
	}
}
